package bx.job.jobstore.bean;

import akka.actor.typed.ActorRef;
import bx.job.actors.JobLogActor;
import bx.job.entity.BxJobInfo;
import bx.job.entity.BxLogInfo;
import bx.job.entity.BxTriggerInfo;
import com.google.common.collect.Sets;
import lombok.Builder;
import lombok.Data;

import java.util.Set;

@Builder
@Data
public class JobInfoContextBean {

    private BxJobInfo bxJobInfo;

    private BxTriggerInfo triggerInfo;

    private BxLogInfo logInfo; // 日志保存成功后生效

    private Set<String> failedWorkerAddrInfo; // 保存当前已经失败的 worker 地址列表，若从数据库中获取最新的列表跟该列表相同，那么设置调度失败，不再重试，仅在失败时有效

    private ActorRef<JobLogActor.JobIssueActorMsg> logActor;

    // 一个任务只会由一个 actor 完成，所以该方法线程安全
    public Set<String> getFailedWorkerAddrInfo() {
        if (failedWorkerAddrInfo == null) {
            failedWorkerAddrInfo = Sets.newHashSet();
        }
        return failedWorkerAddrInfo;
    }
}
